package com.vshop.platform.system.crud.service;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.vshop.framework.core.util.MapstructUtil;
import com.vshop.framework.mybatisflex.page.PageData;
import com.vshop.framework.mybatisflex.page.PageQuery;
import com.vshop.platform.system.crud.dao.SysOperLogDao;
import com.vshop.platform.system.domain.entity.SysOperLog;
import com.vshop.platform.system.domain.param.SysOperLogParam;
import com.vshop.platform.system.domain.vo.SysOperLogVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@RequiredArgsConstructor
@Service
public class SysOperLogService {

    private final SysOperLogDao sysOperLogDao;

    public PageData<SysOperLogVo> page(SysOperLogParam param, PageQuery pageQuery) {
        QueryWrapper queryWrapper = sysOperLogDao.buildQueryWrapper(param);
        Page<SysOperLogVo> page = sysOperLogDao.pageAs(pageQuery.build(), queryWrapper, SysOperLogVo.class);
        return PageData.build(page);
    }

    public boolean save(SysOperLogParam param) {
        SysOperLog entity = MapstructUtil.convert(param, SysOperLog.class);
        entity.setOperTime(LocalDateTimeUtil.now());
        return sysOperLogDao.save(entity);
    }
}
